package com.wn.pettyloan.controller;

import com.wn.pettyloan.dto.ProductAndDocumnetTypeDto;
import com.wn.pettyloan.entity.ProductAndDocumnetType;
import com.wn.pettyloan.service.ProductAndDocumnetTypeService;
import com.wn.pettyloan.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: pettyloan
 * @ClassName ProductAndDocumnetTypeController
 * @description: 产品所需材料
 * @author: 国雨浓
 * @create: 2022-12-12 14:13
 **/
@RestController
@RequestMapping("PAD")
public class ProductAndDocumnetTypeController {
    @Resource
    private ProductAndDocumnetTypeService productAndDocumnetTypeService;
    
    /*
      * @Author 国雨浓
      * @Description  添加产品所需材料
      * @Date 14:18 2022/12/12
      * @Param 
      * @return 
      **/
    @PostMapping("/add")
    public Result add(@RequestBody ProductAndDocumnetType productAndDocumnetType){
        int i = productAndDocumnetTypeService.insertSelective(productAndDocumnetType);
        if (i > 0) {
            return Result.ok();
        }else {
            return Result.error("");
        }
    }

    /*
      * @Author 国雨浓
      * @Description  添加多个产品所需材料
      * @Date 15:07 2022/12/12
      * @Param
      * @return 
      **/
    @PostMapping("/Addlist")
    public Result addAll(@RequestBody ProductAndDocumnetTypeDto productAndDocumnetTypeDto){
        productAndDocumnetTypeService.addlist(productAndDocumnetTypeDto);
        return Result.ok();
    }

    /*
      * @Author 国雨浓
      * @Description  根据id删除产品所需材料
      * @Date 14:20 2022/12/12
      * @Param
      * @return
      **/
    @DeleteMapping("{id}")
    public Result delete(@PathVariable()Long id){
        int i = productAndDocumnetTypeService.deleteByPrimaryKey(id);
        return Result.ok();
    }

   /*
     * @Author 国雨浓
     * @Description  根据id查产品所需材料
     * @Date 14:27 2022/12/12
     * @Param
     * @return
     **/
   @GetMapping("{id}")
    public Result selectByid(Long id){
       ProductAndDocumnetType productAndDocumnetType = productAndDocumnetTypeService.selectByPrimaryKey(id);
       return Result.ok();
   }

   /*
     * @Author 国雨浓
     * @Description  查询所有产品所需材料
     * @Date 14:28 2022/12/12
     * @Param 
     * @return 
     **/
   @GetMapping()
    public Result selectAll(){
       List<ProductAndDocumnetType> productAndDocumnetTypes = productAndDocumnetTypeService.selectAll();
       return Result.ok().data("productAndDocumnetTypes",productAndDocumnetTypes);
   }

   /*
     * @Author 国雨浓
     * @Description  根据id修改产品所需材料
     * @Date 14:31 2022/12/12
     * @Param
     * @return
     **/@PutMapping()
    public Result update(@RequestBody ProductAndDocumnetType productAndDocumnetType){
       int i = productAndDocumnetTypeService.updateByPrimaryKeySelective(productAndDocumnetType);
       return Result.ok();
   }

}
